<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>忘记密码 - layuiAdmin</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="../../layuiadmin/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="../../layuiadmin/style/admin.css" media="all">
    <link rel="stylesheet" href="../../layuiadmin/style/login.css" media="all">
</head>

<div class="layadmin-user-login layadmin-user-display-show" id="LAY-user-login" style="display: none;">
    <div class="layadmin-user-login-main">
        <div class="layadmin-user-login-box layadmin-user-login-header">
            <h2>layuiAdmin</h2>
            <p>layui 官方出品的单页面后台管理模板系统</p>
        </div>
        <div class="layadmin-user-login-box layadmin-user-login-body layui-form">

            <script type="text/html" template>
                {{# if(layui.router().search.type === 'resetpass'){ }}
                <div class="layui-form-item">
                    <label class="layadmin-user-login-icon layui-icon layui-icon-password"
                           for="LAY-user-login-password"></label>
                    <input type="text" name="name" id="LAY-user-login-name" lay-verify="required"
                           placeholder="用户名" class="layui-input">
                </div>
                <div class="layui-form-item">
                    <label class="layadmin-user-login-icon layui-icon layui-icon-password"
                           for="LAY-user-login-password"></label>
                    <input type="password" name="password" id="LAY-user-login-password" lay-verify="pass"
                           placeholder="新密码" class="layui-input">
                </div>
                <div class="layui-form-item">
                    <label class="layadmin-user-login-icon layui-icon layui-icon-password"
                           for="LAY-user-login-repass"></label>
                    <input type="password" name="repass" id="LAY-user-login-repass" lay-verify="required"
                           placeholder="确认密码" class="layui-input">
                </div>
                <div class="layui-form-item">
                    <button class="layui-btn layui-btn-fluid" lay-submit lay-filter="LAY-user-forget-resetpass">重置新密码
                    </button>
                </div>
                {{# } else { }}
                <div class="layui-form-item">
                    <label class="layadmin-user-login-icon layui-icon layui-icon-cellphone"
                           for="LAY-user-login-cellphone"></label>
                    <input type="text" name="cellphone" id="LAY-user-login-cellphone" lay-verify="phone"
                           placeholder="请输入注册时的手机号" class="layui-input">
                </div>
                <div class="layui-form-item">
                    <div class="layui-row">
                        <div class="layui-col-xs7">
                            <label class="layadmin-user-login-icon layui-icon layui-icon-vercode"
                                   for="LAY-user-login-vercode"></label>
                            <input type="text" name="vercode" id="LAY-user-login-vercode" lay-verify="required"
                                   placeholder="图形验证码" class="layui-input">
                        </div>
                        <div class="layui-col-xs5">
                            <div style="margin-left: 10px;">
                                <img src="https://www.oschina.net/action/user/captcha"
                                     class="layadmin-user-login-codeimg" id="LAY-user-get-vercode">
                            </div>
                        </div>
                    </div>
                </div>
                <div class="layui-form-item">
                    <div class="layui-row">
                        <div class="layui-col-xs7">
                            <label class="layadmin-user-login-icon layui-icon layui-icon-vercode"
                                   for="LAY-user-login-smscode"></label>
                            <input type="text" name="smsvercode" id="LAY-user-login-smscode" lay-verify="required"
                                   placeholder="短信验证码" class="layui-input">
                        </div>
                        <div class="layui-col-xs5">
                            <div style="margin-left: 10px;">
                                <button type="button" class="layui-btn layui-btn-primary layui-btn-fluid"
                                        id="LAY-user-getsmscode">获取验证码
                                </button>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="layui-form-item">
                    <button class="layui-btn layui-btn-fluid" lay-submit lay-filter="LAY-user-forget-submit">找回密码
                    </button>
                </div>
                {{# } }}
            </script>

        </div>
    </div>

    <div class="layui-trans layadmin-user-login-footer">

        <p>© 2018 <a href="http://www.layui.com/" target="_blank">layui.com</a></p>
        <p>
            <span><a href="http://www.layui.com/admin/#get" target="_blank">获取授权</a></span>
            <span><a href="http://www.layui.com/admin/pro/" target="_blank">在线演示</a></span>
            <span><a href="http://www.layui.com/admin/" target="_blank">前往官网</a></span>
        </p>
    </div>

</div>

<script src="../../layuiadmin/layui/layui.js"></script>
<script>
    layui.config({
        base: '../../layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块

    }).use(['index', 'user'], function () {
        var $ = layui.$
            , setter = layui.setter
            , admin = layui.admin
            , form = layui.form
            , router = layui.router();


        form.render();

        //清除验证码输入框边框的红色提示
        $("#LAY-user-login-smscode").click(function () {
            $("#LAY-user-login-smscode").css({"border": ""})
        });
        //找回密码下一步
        form.on('submit(LAY-user-forget-submit)', function (obj) {
            var field = obj.field;

            //请求接口
            $.ajax({
                url: '/admin/fogotreset' //实际使用请改成服务端真实接口
                , data: field
                , success: function (res) {
                    if (res.code == 200) {
                        location.hash = '/type=resetpass';
                        location.reload();
                    } else if (res.code == 1) {
                        layer.msg('验证失败,验证码错误', {
                            offset: '15px'
                            , icon: 5
                            , time: 1000
                            , success: function () {//弹出成功后 验证码输入框边框变红
                                $("#LAY-user-login-smscode").css({"border": "1px solid red"});
                            }
                        });
                    } else if (res.code == 2) {
                        layer.msg('验证失败,验证码已过期', {
                            offset: '15px'
                            , icon: 5
                            , time: 1000
                            , success: function () {//弹出成功后 验证码输入框边框变红
                                $("#LAY-user-login-smscode").css({"border": "1px solid red"});
                            }
                        });
                    } else {
                        layer.msg('验证失败', {
                            offset: '15px'
                            , icon: 5
                            , time: 1000
                            , success: function () {//弹出成功后 验证码输入框边框变红
                                $("#LAY-user-login-smscode").css({"border": "1px solid red"});
                            }
                        });
                    }


                }
            });

            return false;
        });

        //重置密码
        form.on('submit(LAY-user-forget-resetpass)', function (obj) {
            var field = obj.field;

            //确认密码
            if (field.password !== field.repass) {
                return layer.msg('两次密码输入不一致');
            }

            //请求接口
            $.ajax({
                url: '/admin/passreset', //实际使用请改成服务端真实接口
                data: JSON.stringify(field),
                type: 'post',
                contentType: 'application/json;charset=utf-8',
                datatype: 'json',
                success: function (res) {
                    if(res.code==200){
                        layer.msg('密码已成功重置', {
                            offset: '15px'
                            , icon: 1
                            , time: 1000
                        }, function () {

                        });
                    }else if(res.code==1){
                        layer.msg('用户不存在', {
                            offset: '15px'
                            , icon:5
                            , time: 1000
                        }, function () {

                        });
                    }else if(res.code==2){
                        layer.msg('密码重置错误', {
                            offset: '15px'
                            , icon:5
                            , time: 1000
                        }, function () {

                        });
                    }

                }
            });

            return false;
        });

    });
</script>
</body>
</html>